﻿using System;
using System.Collections.Generic;
using System.Linq;
using WeBlog.Interfaces;

namespace WeBlog.Repositories
{
    public abstract class RepositoryBase<T> where T : class, IModel
    {        
        protected readonly IUnitOfWork Context;

        protected RepositoryBase( IUnitOfWork unitOfWork )
        {
            Context = unitOfWork;  
        }

        public IQueryable<T> FindAll()
        {
            return Context.DbSet<T>();
        }

        public T Find(params object[] keyValues )
        {
            return Context.Find<T>(keyValues);
        }

        public virtual void Remove(T entity)
        {
            Context.Remove(entity);
        }

        public virtual void Add(T entity)
        {
            Context.Add(entity);
        }  
      
        public void Attach(T entity)
        {
            Context.Attach(entity);            
        }
    }    
}
